package com.liuning.droolsdemo;

import com.drools.core.KieTemplate;
import com.liuning.droolsdemo.entity.UserInfo;
import org.junit.Before;
import org.junit.jupiter.api.Test;
import org.kie.api.runtime.KieSession;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;

@SpringBootTest
public class Demo4 {

    @Resource
    private KieTemplate kieTemplate;


    @Before
    public void before() throws InterruptedException {
        Thread.sleep(1000);
    }

    @Test
    public void test01() {
        KieSession session = kieTemplate.getKieSession("rule4.drl");
        UserInfo userInfo = new UserInfo();
        LocalDateTime startTime = LocalDateTime.of(2022, 4, 5, 9, 27);
        LocalDateTime endTime = LocalDateTime.of(2022, 5, 15, 9, 27);
        LocalDateTime now = LocalDateTime.now();
        userInfo.setStartTime(startTime);
        userInfo.setEndTime(endTime);
        Duration duration = Duration.between(startTime, now);
        System.out.println("duration:" + duration.toMillis());

        boolean isBefore = startTime.isBefore(now) && endTime.isAfter(now);
        System.out.println("是否在当前日期之前：" + isBefore + " ,是否在当前之后：" + isBefore);

        session.insert(userInfo);
        int i = session.fireAllRules();
        System.out.println("i:" + i);

        System.out.println("userInfo:" + userInfo);

    }

    @Test
    public void test02() {
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime servenTime = now.plusDays(7l);

        System.out.println(now + "===" + servenTime);

        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String format = now.format(dateTimeFormatter);
        System.out.println(format);

    }

}
